package com.guldan.auth.provider.service;

import com.guldan.auth.provider.common.constans.Constant;
import com.guldan.auth.provider.dto.StaffDTO;
import com.guldan.auth.provider.dto.users.NavigationDTO;
import com.guldan.auth.provider.dto.users.UserSearchDTO;
import com.guldan.auth.provider.dto.users.UsersDTO;
import com.guldan.auth.provider.manager.UsersManager;
import com.guldan.auth.provider.service.IStaffService;
import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.redis.CacheService;
import com.guldan.core.search.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by Silas.
 * Date: 2016/10/2
 * Time: 0:58
 */
@Component
public class StaffServiceImpl implements IStaffService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private CacheService cacheService;

    @Autowired
    private UsersManager usersManager;

    @Override
    public ResponseDTO<Boolean> authentication(String var1) {
        return null;
    }

    @Override
    public ResponseDTO<UsersDTO> findById(Integer userId) {
        ResponseDTO<UsersDTO> responseDTO = new ResponseDTO<>();
        responseDTO.setData(usersManager.get(userId));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<UsersDTO>> findByUserName(String var1) {
        return null;
    }

    @Override
    public ResponseDTO<Pagination<UsersDTO>> findByPaging(UserSearchDTO var1) {
        return null;
    }

    @Override
    public ResponseDTO<List<String>> getPermissions(Integer var1) {
        return null;
    }

    @Override
    public ResponseDTO<List<NavigationDTO>> getAuthenticatedMenu(Integer var1) {
        return null;
    }

    /*@Override
    public StaffDTO getStaffDTO(int staffId) {
        StaffDTO dto = new StaffDTO();
        dto.setId(10001);
        dto.setStaffName("silas hello");
        return dto;
    }

    @Override
    public boolean authentication(String JSESSIONID) {

        logger.info("Login Check, JSESSIONID=[" + JSESSIONID + "]");

        Map<Object, Object> users = cacheService.hMap(Constant.KEY_LOGINUSER);
        if (users == null) {
            users = new HashMap<Object, Object>();
            cacheService.hputs(Constant.KEY_LOGINUSER, new HashMap<String, String>());
        }

        logger.info("Login User Size: " + users.size());
        Iterator it = users.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();

            logger.info("username=[" + entry.getKey() + "], JSESSIONID=[" + entry.getValue() + "]");

            if (entry.getValue().equals(JSESSIONID)) {
                //已经登录过
                return true;
            }
        }
        return false;
    }*/


}
